﻿

<title>DNS授权</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>DNS授权</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-dnsauth-formlist">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">DNS服务商</label>
                    <div class="layui-input-block">
                        <select name="dnsProviderType">
                            <option value="">不限</option>
                            <option value="1">阿里云</option>
                            <option value="2">腾讯云</option>
                            <option value="3">华为云</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">DNS授权ID</label>
                    <div class="layui-input-block">
                        <input type="text" name="dnsAuthId" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">AccessKeyID</label>
                    <div class="layui-input-block">
                        <input type="text" name="accessKeyId" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-dnsauth-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
            </div>

            <table id="LAY-dnsauth-manage" lay-filter="LAY-dnsauth-manage"></table>
            <script type="text/html" id="dnsProviderTpl">
                {{# if(d.dnsProviderType==1){ }}
                <img style="display: inline-block;" src="/res/style/imgs/ali_clound.png">
                <span>{{ d.dnsProviderTypeStr }}</span>
                {{# }else if(d.dnsProviderType==2){ }}
                <img style="display: inline-block;" src="/res/style/imgs/tencent_clound.png">
                <span>{{ d.dnsProviderTypeStr }}</span>
                {{# }else if(d.dnsProviderType==3){ }}
                <img style="display: inline-block;" src="/res/style/imgs/huawei_clound.png">
                <span>{{ d.dnsProviderTypeStr }}</span>
                {{# }else{ }}
                <span>{{ d.dnsProviderTypeStr }}</span>
                {{#  } }}
            </script>
            <script type="text/html" id="dnsAuthIdTpl">
                <span>{{ d.dnsAuthId }}</span>
                <br />
                <span>{{ d.dnsAuthName }}</span>
            </script>
            <script type="text/html" id="table-dnsauth-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script>
    layui.use('dnsauth', layui.factory('dnsauth')).use(['admin', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , setter = layui.setter
            , view = layui.view
            , table = layui.table
            , form = layui.form;

        form.render(null, 'layadmin-dnsauth-formlist');

        //开启搜索
        form.on('submit(LAY-dnsauth-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-dnsauth-manage', {
                where: field
            });
        });

        //事件
        var active = {
            add: function () {
                admin.popup({
                    title: '添加DNS授权'
                    , area: ['600px', '500px']
                    , id: 'LAY-popup-dnsauth-add'
                    , success: function (layero, index) {
                        view(this.id).render('dns/dnsauthform').done(function () {
                            form.render(null, 'layuiadmin-form-dnsauthadmin');

                            //开启提交
                            form.on('submit(LAY-dnsauth-front-submit)', function (data) {
                                var field = data.field; //获取提交的字段

                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                $.ajax({
                                    url: setter.baseConfig.apiHost + '/api/dnsauth/add' //实际使用请改成服务端真实接口
                                    , type: 'post'
                                    , contentType: "application/json"
                                    , data: JSON.stringify(field)
                                    , beforeSend: function (xhr) {
                                        xhr.setRequestHeader("Authorization", 'Bearer ' + layui.data(setter.tableName)[setter.request.tokenName]);
                                    }
                                    , success: function (res) {
                                        if (res.errorCode != '00000') {
                                            layer.msg(res.errorMessage, {
                                                offset: '15px'
                                                , icon: 2
                                                , time: 3000
                                            });

                                            return false;
                                        }

                                        //登入成功的提示与跳转
                                        layer.msg('添加成功', {
                                            offset: '15px'
                                            , icon: 1
                                            , time: 1000
                                        });

                                        layui.table.reload('LAY-dnsauth-manage'); //重载表格
                                        layer.close(index); //执行关闭
                                    }
                                });
                                
                            });
                        });
                    }
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        
    });
</script>